#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	vector<int> nums = { 3,2,1 };
	for (auto num : nums) cout << num << " ";
	cout << '\n';
	while (prev_permutation(nums.begin(),nums.end())){
		for (auto num : nums) cout << num << " ";
		cout << '\n';
	}
	return 0;
}